﻿@{
    var galleryId = UrlData[0].AsInt();

    var db = Database.Open("PhotoGallery");

    var gallery = db.QuerySingle("SELECT * FROM Galleries WHERE Id = @0", galleryId);
    if (gallery == null) {
        Response.SetStatus(HttpStatusCode.NotFound);
        return;
    }

    // Found a match - so show all its photos
    var photos = db.Query("SELECT Id, FileTitle FROM Photos WHERE GalleryId = @0", galleryId).ToList();

    Page.Title = "Gallery - " + gallery.Name;
}
	
<h1>@gallery.Name</h1>

@if (photos.Count == 1) {
    <p>This gallery contains one photo.</p>
} else {
    <p>This gallery contains @photos.Count photos.</p>
}

<ul class="thumbnails">
    @foreach (var photo in photos) {
        <li>
            <a href="@Href("~/Photo/View", photo.Id)">
                <img alt="thumbnail of @Path.GetFileNameWithoutExtension(photo.FileTitle)" src="@Href("~/Photo/Thumbnail", photo.Id)" class="thumbnail-border" />
                <span class="image-overlay">@Path.GetFileNameWithoutExtension(photo.FileTitle)</span>
            </a>
        </li>
    }
</ul>

@if (WebSecurity.IsAuthenticated) {
    <p class="actions">
        <a href="@Href("~/Gallery/Upload", galleryId)">Upload a Photo</a>
    </p>
}